package com.nuoniu.sibanyun.service.crm.call.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.config.YmlConfig;
import com.nuoniu.sibanyun.entity.crm.CrmLinkman;
import com.nuoniu.sibanyun.entity.crm.call.*;
import com.nuoniu.sibanyun.entity.crm.call.dto.*;
import com.nuoniu.sibanyun.entity.crm.call.dto.xiangyun.CallBackRecord;
import com.nuoniu.sibanyun.entity.crm.call.dto.xiangyun.SelfData;
import com.nuoniu.sibanyun.entity.crm.call.rongying.CallMode;
import com.nuoniu.sibanyun.entity.crm.call.rongying.RongYingCallResult;
import com.nuoniu.sibanyun.entity.expenses.ExpensesAccount;
import com.nuoniu.sibanyun.entity.msg.SysMsg;
import com.nuoniu.sibanyun.mapper.crm.call.CrmCallTaskRecordMapper;
import com.nuoniu.sibanyun.service.crm.ICrmLinkmanService;
import com.nuoniu.sibanyun.service.crm.call.*;
import com.nuoniu.sibanyun.service.msg.ISysMsgService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import com.nuoniu.sibanyun.utils.FileUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * <p>
 * 客户管理-外呼管理-外呼记录 服务实现类
 * </p>
 *
 * @author 白强
 * @since 2022-02-28
 */
@Service
@Log4j2
public class CrmCallTaskRecordServiceImpl extends ServiceImpl<CrmCallTaskRecordMapper, CrmCallTaskRecord> implements ICrmCallTaskRecordService {

    /** 校验 数字 用逗号 隔开 的字符串 */
    private static final String STR_ENG_PATTERN="^\\d+(,\\d+)*$";
    @Autowired
    private ICrmCallTaskDetailService callTaskDetailService;
    @Autowired
    private ICrmCallTaskService crmCallTaskService;
    @Autowired
    private ServletContext servletContext;
    @Autowired
    private ICrmCallMinutesService callMinutesService;
    @Autowired
    @Lazy
    private ISysMsgService sysMsgService;
    @Autowired
    @Lazy
    private ICrmLinkmanService linkmanService;


    @Override
    public List<CrmCallTaskRecord> listByTaskId(Integer taskId) {
        UserInfo userInfo = UserThreadLocal.get();
        QueryWrapper<CrmCallTaskRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("crm_call_task_id",taskId);
        queryWrapper.eq("company_id",userInfo.getCompanyId());
        queryWrapper.eq("create_user_id",userInfo.getUserId());
        return  list(queryWrapper);
    }

    @Override
    public Page<CrmCallTaskRecord> pageList(CrmCallTaskRecordSearchDto recordSearchDto) {
        Page<CrmCallTaskRecord> page = recordSearchDto.getPage();
        UserInfo userInfo = UserThreadLocal.get();
        String createUserIds = recordSearchDto.getCreateUserIds();
        if(StringUtils.isNotBlank(createUserIds) && !createUserIds.matches(STR_ENG_PATTERN))throw new NuoNiuException("参数错误");
        Page<CrmCallTaskRecord> crmCallTaskRecordPage = baseMapper.pageList(page,userInfo.getCompanyId(), recordSearchDto);
        return crmCallTaskRecordPage;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void addCallBackInfo(CrmCallTaskRecordCallBackDto crmCallTaskRecordCallBackDto) {
        log.debug("接收到 语音盒子 回调信息;{}",JSON.toJSONString(crmCallTaskRecordCallBackDto));
        CrmCallTaskRecord crmCallTaskRecord = new CrmCallTaskRecord();
        crmCallTaskRecord.setServiceProvider("YW");
        String type = crmCallTaskRecordCallBackDto.getType();
        if("calllog".equals(type)){
            List<CrmCallTaskRecordCallBackContent> contentList = crmCallTaskRecordCallBackDto.getContent();
            if(contentList.size() == 0)return;
            CrmCallTaskRecordCallBackContent content = contentList.get(0);
            String extraparam = content.getExtraparam();
            String callId = content.getCallId();
            /** 获取存在的通话记录ID */
            Long recordId = this.getByCallId(callId);
            Long detailId = null;
            Integer taskId = null;

            String callDirection = content.getCallDirection();
            String callFlag = content.getCallFlag();
            String duration = content.getDuration();
            if(StringUtils.isNotBlank(extraparam)){
                CrmCallTaskDetail callTaskDetail = JSON.parseObject(extraparam, CrmCallTaskDetail.class);
                if(null != callTaskDetail){
                    detailId = callTaskDetail.getId();
                    taskId = callTaskDetail.getCrmCallTaskId();
                    BeanUtils.copyProperties(callTaskDetail,crmCallTaskRecord);
                    crmCallTaskRecord.setTalkId(callId);

                }
            }
            //通话类型 0 呼入 1呼出
            if("0".equals(callDirection)){
                crmCallTaskRecord.setCallType(0);

                crmCallTaskRecord.setCrmCallTaskId(null);
                crmCallTaskRecord.setCrmCallTaskName(null);
                crmCallTaskRecord.setCrmId(null);
                crmCallTaskRecord.setCrmName(null);
                crmCallTaskRecord.setLinkManId(null);
                crmCallTaskRecord.setLinkManName(null);
            }else if("1".equals(callDirection)){
                crmCallTaskRecord.setCallType(1);

            }
            // 0 未接通 1 已接通
            if("0".equals(callFlag)){
                crmCallTaskRecord.setCallResult(0);
            }else if("1".equals(callFlag)){
                crmCallTaskRecord.setCallResult(1);
            }
            crmCallTaskRecord.setCallStatus(true);
            if(StringUtils.isNotBlank(duration)){
                crmCallTaskRecord.setTalkTime(Integer.valueOf(duration));
            }
            //主叫号码
            crmCallTaskRecord.setCaller(content.getCaller());
            //被叫号码
            crmCallTaskRecord.setCallee(content.getCallee());
            content.setExtraparam(null);
            crmCallTaskRecord.setCallBackJson(JSON.toJSONString(content));
            crmCallTaskRecord.setId(recordId);
            crmCallTaskRecord.setCreateDate(LocalDateTime.now());
            this.saveOrUpdate(crmCallTaskRecord);
            if(null != detailId){
                this.updateTaskAndDetailStatistics(crmCallTaskRecord,detailId,taskId);
            }
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void uploadAudio(HttpServletRequest request, String callId, String pid, String IMEI) throws Exception {
        log.debug("接收到 语音盒子 录音 信息");
        MultipartResolver mr = new CommonsMultipartResolver(servletContext);
        MultipartFile multipartFile = null;
        if( mr.isMultipart(request)){
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;
            Iterator<String> iter = multiRequest.getFileNames();
            if (iter.hasNext()) {
                multipartFile = multiRequest.getFile(iter.next());
            }
        }
        if(null == multipartFile){
            log.info("获取不到语音文件");
            return;
        }
        InputStream inputStream = multipartFile.getInputStream();

        String fileName = multipartFile.getOriginalFilename();  //文件名字
        if(StringUtils.isBlank(callId)){
            log.info("自动推送语音，语音ID为空，IMEI：{}",IMEI);
            return;
        }
        String classDir = "audio/";
        if(StringUtils.isNotBlank(pid)){
            classDir += pid + "/";
        }
        String uploadPath = FileUtils.upload(inputStream, 2, classDir,fileName);

        if(StringUtils.isNotBlank(uploadPath)){
            uploadPath = YmlConfig.DOWNLOAD_FILE_URL + uploadPath;
            Long recordId = this.getByCallId(callId);
            CrmCallTaskRecord crmCallTaskRecord = new CrmCallTaskRecord();
            crmCallTaskRecord.setId(recordId);
            crmCallTaskRecord.setTalkId(callId);
            crmCallTaskRecord.setCallAudioPath(uploadPath);
            this.saveOrUpdate(crmCallTaskRecord);
        }
    }

    @Override
    public void callBackRecordFromXiangYun(CallBackRecord callBackRecord) {
        String callid = callBackRecord.getCallid();
        if(null == callid)throw new NuoNiuException("话单id不能为空");
//        log.debug("接收到祥云推送的话单;{}",JSON.toJSONString(callBackRecord));
        Long detailId = null;
        Integer taskId = null;
        String riskType = callBackRecord.getRiskType();                     //风控类型 1:正常呼叫，2:使用补线    3:拒绝呼叫 ， 4:配置有问题             原因从reason中取
        String resulttype = callBackRecord.getResulttype();                 //拨打结果类型 1:成功 2：失败
        String callResult = callBackRecord.getCallResult();                 //呼叫结果 0 未接通坐席未接 1 未接通用户拒接 2 未接通用户不可达 3 未接通坐席取消 4 接通坐席挂断  5 接通用户挂断 6 未接通系统挂断 6.1 无可用坐席 6.2 语音通知场景语音播放完系统自动挂断  7 未接通用户取消 8 未接通用户未接 99 双呼成功
        String callResultState = callBackRecord.getCallResultState();       //呼叫结果说明
        CrmCallTaskRecord crmCallTaskRecord = new CrmCallTaskRecord();
        crmCallTaskRecord.setServiceProvider("XY");
        if(StringUtils.isNotBlank(riskType)){
            crmCallTaskRecord.setRiskType(Integer.valueOf(riskType));
        }
        if(StringUtils.isNotBlank(callResult)){
            crmCallTaskRecord.setCallResultState(callResult);
        }
        if(StringUtils.isNotBlank(callResultState)){
            crmCallTaskRecord.setCallResultStateRemark(callResultState);
        }
        crmCallTaskRecord.setCallStatus(true);
        /** 外呼线路 默认 呼入 */
        crmCallTaskRecord.setCallType(1);
        // 0 未接通 1 已接通
        if("2".equals(resulttype)){
            crmCallTaskRecord.setCallResult(0);
        }else if("1".equals(resulttype)){
            crmCallTaskRecord.setCallResult(1);
        }
        crmCallTaskRecord.setCallee(callBackRecord.getCalled());
        crmCallTaskRecord.setCaller(callBackRecord.getCaller());
        crmCallTaskRecord.setTalkId(callid);
        if(StringUtils.isNotBlank(callBackRecord.getBillSec())){
            crmCallTaskRecord.setTalkTime(Integer.valueOf(callBackRecord.getBillSec()));
        }else {
            crmCallTaskRecord.setTalkTime(0);
        }
        /** 当前使用分钟数*/
        Integer usedMinutes =  crmCallTaskRecord.getTalkTime() / 60 + (crmCallTaskRecord.getTalkTime() % 60 > 0 ? 1: 0);
        crmCallTaskRecord.setUsedMinutes(usedMinutes);
        crmCallTaskRecord.setCallAudioPath(callBackRecord.getRecordingUrl());
        /** 处理 前端拨打 自定义参数（任务明细） */
        String selfdata = callBackRecord.getSelfdata();
        log.debug("祥云话单推送：自定义字段：{}",selfdata);
        if(StringUtils.isNotBlank(selfdata)){
                    SelfData selfData = JSON.parseObject(selfdata, SelfData.class);
            Integer taskDetailId = selfData.getTdId();
            Integer linkManId = selfData.getLId();
            Integer userId = selfData.getUId();
            String userName = selfData.getUName();
            crmCallTaskRecord.setCreateUserId(userId);
            crmCallTaskRecord.setCreateUserName(userName);
            if(null != taskDetailId){
                CrmCallTaskDetail callTaskDetail = callTaskDetailService.getById(taskDetailId);
                if(null != callTaskDetail){
                    detailId = callTaskDetail.getId();
                    taskId = callTaskDetail.getCrmCallTaskId();
                    BeanUtils.copyProperties(callTaskDetail,crmCallTaskRecord);
                }
            }else{
                if(null != linkManId){
                    CrmLinkman crmLinkman = linkmanService.getById(linkManId);
                    crmCallTaskRecord.setCompanyId(crmLinkman.getCompanyId());
                    crmCallTaskRecord.setCrmId(crmLinkman.getCrmId());
                    crmCallTaskRecord.setCrmName(crmLinkman.getCrmName());
                    crmCallTaskRecord.setLinkManId(linkManId);
                    crmCallTaskRecord.setLinkManName(crmLinkman.getName());
                }
            }
        }
        callBackRecord.setSelfdata(null);
        crmCallTaskRecord.setCallBackJson(JSON.toJSONString(callBackRecord));
        crmCallTaskRecord.setCreateDate(LocalDateTime.now());
        this.saveOrUpdate(crmCallTaskRecord);
        if(null != detailId){
            this.updateTaskAndDetailStatistics(crmCallTaskRecord,detailId,taskId);
        }
        /** 接通后，计费*/
        if("1".equals(resulttype)){
            this.chargingAndBill(crmCallTaskRecord);
        }
    }

    /**
     *  更新 任务统计
     * @param crmCallTaskRecord
     * @param detailId
     * @param taskId
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void updateTaskAndDetailStatistics(CrmCallTaskRecord crmCallTaskRecord, Long detailId, Integer taskId) {
        CrmCallTaskDetailUpdateDto crmCallTaskDetailUpdateDto = new CrmCallTaskDetailUpdateDto();
        crmCallTaskDetailUpdateDto.setCompanyId(crmCallTaskRecord.getCompanyId());
        crmCallTaskDetailUpdateDto.setCrmCallTaskDetailId(detailId);
        crmCallTaskDetailUpdateDto.setLastCallStatus(crmCallTaskRecord.getCallStatus());
        crmCallTaskDetailUpdateDto.setLastCallTime(LocalDateTime.now());
        crmCallTaskDetailUpdateDto.setCallCount(1);
        Integer callResult = crmCallTaskRecord.getCallResult();
        if(null != callResult && 1 == callResult){
            crmCallTaskDetailUpdateDto.setLastCallResult(callResult);
            crmCallTaskDetailUpdateDto.setConnectCount(1);
            crmCallTaskDetailUpdateDto.setTalkTime(crmCallTaskRecord.getTalkTime());
        }
        callTaskDetailService.updateDetailSateAndCount(crmCallTaskDetailUpdateDto);
        /** 更新 任务进行状态*/
        if(null !=taskId){
            CrmCallTask crmCallTask = crmCallTaskService.getById(taskId);
            crmCallTaskService.updateTaskStatus(crmCallTask);
        }
    }

    /**
     * 计算话费、更新账单、余额不足校验
     * @param crmCallTaskRecord
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void chargingAndBill(CrmCallTaskRecord crmCallTaskRecord) {
        Integer companyId = crmCallTaskRecord.getCompanyId();
        Integer callResult = crmCallTaskRecord.getCallResult();
        if(callResult.equals(0))return;
        String serviceProvider = crmCallTaskRecord.getServiceProvider();
        /** 如果是亿维  就返回*/
        if("YW".equals(serviceProvider))return;
        /** 1.查询套餐信息 */
        CrmCallMinutes callMinutes = callMinutesService.getByCompany(companyId,false);
        if(null == callMinutes){
            log.info("外呼功能未开通");
            return;
        }
        Integer status = callMinutes.getStatus();
        if(!status.equals(1)){
            log.info("外呼功能已经失效");
            return;
        }
        Integer usedMinutes = crmCallTaskRecord.getUsedMinutes();
        Integer usedGeneralMinutes = usedMinutes;
        /** 剩余套餐分钟数*/
        Integer baseMinutesRemain = callMinutes.getBaseMinutesRemain();
        if(baseMinutesRemain > usedMinutes){
            callMinutes.setBaseMinutesUsed(callMinutes.getBaseMinutesUsed() + usedMinutes);
            callMinutes.setBaseMinutesRemain(baseMinutesRemain - usedMinutes);
            usedGeneralMinutes = usedGeneralMinutes - usedMinutes;
        }else if(baseMinutesRemain > 0){
            SysMsg sysMsg = new SysMsg();
            sysMsg.setCompanyId(companyId);
            sysMsg.setType(0);
            sysMsg.setTitle("套餐分钟数不足预警");
            sysMsg.setContent("你的套餐分钟数已为0,将使用通用分钟数");
            sysMsg.setCreateDate(LocalDateTime.now());
            sysMsgService.sendMsg(sysMsg);

            callMinutes.setBaseMinutesUsed(callMinutes.getBaseMinutesTotal());
            callMinutes.setBaseMinutesRemain(0);
            usedGeneralMinutes = usedGeneralMinutes - baseMinutesRemain;

        }
        /** 扣除 通用分钟数*/
        if(usedGeneralMinutes > 0){
            callMinutes.setGeneralMinutesUsedMonth(callMinutes.getGeneralMinutesUsedMonth() + usedGeneralMinutes);
            callMinutes.setGeneralMinutesUsed(callMinutes.getGeneralMinutesUsed() + usedGeneralMinutes);
            callMinutes.setGeneralMinutesRemain(callMinutes.getGeneralMinutesRemain() - usedGeneralMinutes);
            if(callMinutes.getGeneralMinutesRemain() < 0){
//                callMinutes.setStatus(0);
                try {
                    SysMsg sysMsg = new SysMsg();
                    sysMsg.setCompanyId(companyId);
                    sysMsg.setType(0);
                    sysMsg.setTitle("外呼功能暂停通知");
                    sysMsg.setContent("你的通用分钟数已经小于0，请及时购买通用分钟数以激活外呼功能");
                    sysMsg.setCreateDate(LocalDateTime.now());
                    sysMsgService.sendMsg(sysMsg);
                }catch (Exception e){
                    log.info("发送‘外呼功能暂停通知’失败！");
                }
            }
        }
        callMinutesService.updateById(callMinutes);
    }

    @Override
    @Async
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void addFromCallMode(UserInfo userInfo, CrmCallAgent myCrmCallAgent, CallMode callMode, RongYingCallResult rongYingCallResult) {
        Integer userId = userInfo.getUserId();
        String userName = userInfo.getUserName();
        Integer companyId = userInfo.getCompanyId();
        //主叫号码
        String Caller = myCrmCallAgent.getPhone();
        String Callee = callMode.getCallee();  //被叫号码
        String businessType = callMode.getBusinessType(); //业务类型：callTask 外呼任务；callLinkMan 直呼联系人；temporary：临时拨打
        String businessJson = callMode.getBusinessJson();
        String sessionId = rongYingCallResult.getSessionId();
        CrmCallTaskRecord crmCallTaskRecord = new CrmCallTaskRecord();
        crmCallTaskRecord.setCallAppId(userInfo.getCallAppId());
        crmCallTaskRecord.setServiceProvider("RongYing");
        crmCallTaskRecord.setTalkId(sessionId);
        crmCallTaskRecord.setCallee(Callee);
        crmCallTaskRecord.setCaller(Caller);
        crmCallTaskRecord.setCompanyId(companyId);
        crmCallTaskRecord.setCreateUserId(userId);
        crmCallTaskRecord.setCreateUserName(userName);
        crmCallTaskRecord.setCreateDate(LocalDateTime.now());
        crmCallTaskRecord.setCallStatus(true);
        crmCallTaskRecord.setCallResult(-1);    // 未处理
        crmCallTaskRecord.setCallType(1);       // 通话类型 0 呼入 1呼出
        CrmCallTaskDetail callTaskDetail = JSON.parseObject(businessJson, CrmCallTaskDetail.class);
        crmCallTaskRecord.setCompanyId(callTaskDetail.getCompanyId());
        crmCallTaskRecord.setCrmId(callTaskDetail.getCrmId());
        crmCallTaskRecord.setCrmName(callTaskDetail.getCrmName());
        crmCallTaskRecord.setLinkManId(callTaskDetail.getLinkManId());
        crmCallTaskRecord.setLinkManName(callTaskDetail.getLinkManName());
        switch (businessType){
            case "callTask":
                if(null != callTaskDetail){
                    crmCallTaskRecord.setCrmCallTaskId(callTaskDetail.getCrmCallTaskId());
                    crmCallTaskRecord.setCrmCallTaskName(callTaskDetail.getCrmCallTaskName());
                    crmCallTaskRecord.setCrmCallTaskDetailId(callTaskDetail.getId());
                }
                break;
            case "callLinkMan":

                break;
        }
        crmCallTaskRecord.setCreateDate(LocalDateTime.now());
        this.save(crmCallTaskRecord);
//                if(null != detailId){
//                    crmCallTaskRecordService.updateTaskAndDetailStatistics(crmCallTaskRecord,detailId,taskId);
//                }
    }


    @Override
    public Long getByCallId(String callId) {
        if(StringUtils.isBlank(callId))return null;
        Long recordId = baseMapper.getByCallId(callId);
        return recordId;
    }

    @Override
    public CrmCallTaskRecord getRecordByTalkId(String talkId) {
        if(StringUtils.isBlank(talkId))return null;
        QueryWrapper<CrmCallTaskRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("call_result",-1);
        queryWrapper.eq("talk_id",talkId);
        queryWrapper.last("LIMIT 1");
        CrmCallTaskRecord record = getOne(queryWrapper, false);
        return record;
    }

    @Override
    public void downAudioRemote(List<CrmCallTaskRecord> crmCallTaskRecordList) {
        int size = crmCallTaskRecordList.size();
        List<CrmCallTaskRecord> updateList = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            CrmCallTaskRecord crmCallTaskRecord = crmCallTaskRecordList.get(i);
            String callAudioRemotePath = crmCallTaskRecord.getCallAudioRemotePath();
            InputStream is = null;
            try {
                // 构造URL
                java.net.URL url = new java.net.URL(callAudioRemotePath);
                // 打开连接
                URLConnection con = url.openConnection();
                // 输入流
                is = con.getInputStream();
                String fileName = "1";
                String classDir = "audio/RongYing/";
                String uploadPath = FileUtils.upload( is, 1, classDir,fileName);
                if(StringUtils.isNotBlank(uploadPath)){
                    crmCallTaskRecord.setCallAudioPath(uploadPath);
                    crmCallTaskRecord.setCrmId(null);
                    crmCallTaskRecord.setCrmName(null);
                    crmCallTaskRecord.setCallee(null);
                    crmCallTaskRecord.setCaller(null);
                    crmCallTaskRecord.setCrmCallTaskId(null);
                    crmCallTaskRecord.setCrmCallTaskName(null);
                    crmCallTaskRecord.setLinkManId(null);
                    crmCallTaskRecord.setLinkManName(null);
                    crmCallTaskRecord.setCallAudioRemotePath(null);
                    crmCallTaskRecord.setCompanyId(null);
                    crmCallTaskRecord.setCreateUserId(null);
                    crmCallTaskRecord.setCreateUserName(null);
                    crmCallTaskRecord.setCreateUserName(null);
                    crmCallTaskRecord.setCallResult(null);
                    crmCallTaskRecord.setCallResultState(null);
                    crmCallTaskRecord.setCallResultStateRemark(null);
                    crmCallTaskRecord.setTalkTimeStr(null);
                    crmCallTaskRecord.setRiskReason(null);
                    crmCallTaskRecord.setGender(null);
                    crmCallTaskRecord.setCallBackJson(null);
                    crmCallTaskRecord.setCallType(null);
                    crmCallTaskRecord.setRiskType(null);
                    crmCallTaskRecord.setCallStatus(null);
                    crmCallTaskRecord.setUsedMinutes(null);
                    crmCallTaskRecord.setTalkId(null);
                    crmCallTaskRecord.setServiceProvider(null);
                    updateList.add(crmCallTaskRecord);
                }
            }catch (Exception e){
                log.error("批量下载 远端 语音文件,错误：{}",e.getMessage());
            }finally{
                if (null != is){
                    try {
                        is.close();
                    } catch (IOException e) {
                        log.error("批量下载 远端 语音文件,关闭输入流异常：{}",e.getMessage());
                    }
                }
            }
        }
        if(updateList.size() > 0){
            this.updateBatchById(updateList);
        }

    }


}
